<?php
(!defined('IN_TOA') || !defined('IN_ADMIN')) && exit('Access Denied!');
/*
	[天生创想] (C)2008-2011 515158 Inc.
	This is NOT a freeware, use is subject to license terms
    URL:http://www.515158.com/
*/

get_config_keytable("office_document_Increase_".getGP('type','G')."");

empty($do) && $do = 'list';
if ($do == 'list') {
	include_once('template/add.php');

} elseif ($do == 'save') {
	
	$savetype = getGP('savetype','P');
	$type = getGP('type','P');
	$title = getGP('title','P');
	$content = getGP('content','P');
	$date = get_date('Y-m-d H:i:s',PHP_TIME);
	$documentid = getGP('documentid','P');
	$annex = getGP('annex','P');
	$uid=$_USER->id;
	if(getGP('readuser','P')!=''){
	$readuser = getGP('readuser','P');
	}else{
	$readuser ="全体人员";
	}
	
	//主表信息
	$document = array(
		'title' => $title,
		'content' => $content,
		'documentid' => $documentid,
		'annex' => $annex,
		'readuser' => $readuser,
		'type' => $type,
		'uid' => $uid,
		'date' => $date,
		'key' => 0
	);
	//写入主表信息
	insert_db('document',$document);
    $id=$db->insert_id();
	//发送提示信息
	//短消息
	if(getGP('sms_info_box_readuser','P')!=''){
	$content=$readuser.':您有一个文件需要阅读,名称为：'.$title.';请进行查看!<a href="admin.php?ac=views&fileurl=document&do=edit&id='.$id.'&type='.$type.'">点击查看>></a>';
	//接收人；内容；类型（1：有返回回值;0：无返回值）;URL
	SMS_ADD_POST($readuser,$content,0,0,$_USER->id);
	}
	//手机短信
	if(getGP('sms_phone_box_readuser','P')!=''){
	$content=$readuser.':您有一个文件需要阅读,请登录OA进行查看!';
	PHONE_ADD_POST(getGP('readuserphone','P'),$content,$readuser,0,0,$_USER->id);
	}
	//$content=$title.get_inc_log(1).$otype.get_inc_log(1).$startdate.get_inc_log(1).$enddate.get_inc_log(1).$content.get_inc_log(1).$type;
	//$title='新建日程信息';
	//get_oa_log_dbadd($id,$content,$title,10,$_USER->id);
	
	goto_page('admin.php?ac=index&fileurl=document&type='.$type.'');

}

//================================================================
function GET_document_PUBLIC_LIST($fatherid=0,$selid=0,$layer=0,$strid=0,$uid=0)
{

	if($_GET[type]=='1'){
			$wheresql=" and uid='".$uid."'";
	}
	$str="";
    global $db;
	$query = $db->query("SELECT * FROM ".DB_TABLEPRE."document_type where father='$fatherid' and type='".$_GET["type"]."' $wheresql ORDER BY id Asc  ");
	
	if(count($query)>0){
	   for($i=0;$i<$layer;$i++){
	   
	   $str.="├";
	   }
	while ($row = $db->fetch_array($query)) {
	
	if($strid!='0'){
		$strnum=$strid.",".$row['id'];
	}
	else{
		$strnum=$row['id'];
	}

	$selstr = $row['id'] == $selid ? 'selected="selected"' : '';
	
	$htmlstr= '<option value="0,'.$strnum.'"  '.$selstr.'>'.$str.$row['title'].'</option>';
	
	echo $htmlstr;
    
	GET_document_PUBLIC_LIST($row['id'],$selid,$layer+1,$strnum);
	
	}

	}
	
   return ;

}

?>